﻿using System;
using System.Windows.Controls;
using Microsoft.Windows.Design.Model;

namespace Peer2PeerControlLibraryWPF.VisualStudio.Design
{
    class Utility
    {

        public static  void _AddItems(ComboBox cb, ModelItem mi, Type typeToAdd, ModelItem adornedElementModelItem, string bindingName)
        {
            Type t = mi.GetCurrentValue().GetType();
            if (typeToAdd == t && mi.Properties["Name"].IsSet)
            {
                int index = cb.Items.Add(mi.Properties["Name"].Value.ToString());

                if (adornedElementModelItem.Properties[bindingName].IsSet)
                {
                    ModelItem binding = adornedElementModelItem.Properties[bindingName].Value;
                    if (binding.Properties["ElementName"].IsSet)
                    {
                        if (mi.Properties["Name"].Value.ToString() == binding.Properties["ElementName"].Value.ToString())
                        {
                            cb.SelectedIndex = index;
                        }
                    }
                }
            }
        }
    }
}
